#include "AppDelegate.h"

#include "cocos2d.h"
#include "SysMenu.h"
#include "SimpleAudioEngine.h"
#include "global.h"
#include "CocosBuilderTest.h"
USING_NS_CC;
using namespace CocosDenshion;
AppDelegate::AppDelegate()
{

}

AppDelegate::~AppDelegate()
{
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
	CCEGLView::sharedOpenGLView()->setDesignResolutionSize(420,700,kResolutionExactFit);
    // turn on display FPS
    pDirector->setDisplayStats(true);
	SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( "SoundStart.mp3" );
	SimpleAudioEngine::sharedEngine()->preloadEffect( "SoundShot.mp3" );
	//SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( CCFileUtils::fullPathFromRelativePath("SoundMove.mp3") );
	SimpleAudioEngine::sharedEngine()->preloadEffect("SoundBoom.mp3" );
	SimpleAudioEngine::sharedEngine()->preloadEffect("SoundMove.mp3" );
	SimpleAudioEngine::sharedEngine()->preloadEffect("SoundMtal.mp3" );
	//SimpleAudioEngine::sharedEngine()->preloadEffect( CCFileUtils::fullPathFromRelativePath(s_shipDestroyEffect) );
	map_level=CCUserDefault::sharedUserDefault()->getIntegerForKey(ID_LEVEL, 1);
	if(map_level<1) map_level=1;
	if(map_level>LEVELS) map_level=LEVELS;
	global_difficult=CCUserDefault::sharedUserDefault()->getBoolForKey(ID_DIFF, true);
	global_sound=CCUserDefault::sharedUserDefault()->getBoolForKey(ID_SOUND, true);
    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
		CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
        cache->addSpriteFramesWithFile("images.plist", "images.png");
    // create a scene. it's an autorelease object
    //pDirector->runWithScene(pScene);

    //CCScene *pScene = CocosBuilderTestScene::scene();//SysMenu::scene();
    CocosBuilderTestScene* s=new CocosBuilderTestScene();s->autorelease();
    s->runThisTest();
	//for(int i=0;i<200;i++)
	//{
	//	float f=-((float)rand()/(RAND_MAX+1.0)*3);
	//	int t=f;
	//	CCLog("rnd=%f %d",f,t);
	//}
    // run
    
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->pause();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->resume();
    
    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
